package com.zuxia.action;

import java.io.UnsupportedEncodingException;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 通用扩展ac，让其可以访问ServletApI（用户的一些请求request、context、和服务器响应response）(并且可以直接获得Servlet API的实例)
 * @author Administrator但是Struts2框架提供了一个轻松的方式访问Servlet API,(直接通过这个ActionContext类)，
 * 但不能直接获得ServletApi实例
 *
 */
public class BaseAction extends ActionSupport implements ServletRequestAware,ServletContextAware,ServletResponseAware {
	private HttpServletRequest request;
	private ServletContext application;
	private HttpServletResponse response;
	/**
	 * 得到session的方法
	 * @return
	 */
	public HttpSession getSession(){
		return request.getSession();
	}
	

	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub必须实现接口的方法
		this.request=arg0;
		try {
			this.request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void setServletContext(ServletContext arg0) {
		// TODO Auto-generated method stub
		this.application=arg0;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response=arg0;
		
		this.response.setCharacterEncoding("utf-8");
		this.response.setContentType("text/html;charset=UTF-8");
	}


	public HttpServletRequest getRequest() {
		return request;
	}


	public ServletContext getApplication() {
		return application;
	}


	public HttpServletResponse getResponse() {
		return response;
	}
}
